<template>
  <div class="box">
    <h2>Son1 子组件</h2>
    从vuex中获取的值: <label>{{this.$store.state.count}}</label>
    <br>
    <button @click="handleAdd(1)">值 + 1</button>
    <button @click="handleAdd(5)">值 + 5</button>
    <button @click="handleAdd(10)">值 + 10</button>
    <button @click="handleChange()">一秒修改成666</button>
    <button @click="changeTitle()">改标题</button>
    <hr>
    <div>{{$store.state.list}}</div>
    <div>{{$store.getters.filterList}}</div>
  </div>
</template>

<script>
// mapState 和 mapGetters 都是映射属性
// mapMutations和mapActions都是映射方法
export default {
  name: 'Son1Com',
  methods: {
    handleAdd(n) {
      /*   // 错误代码(Vue默认不会监测,监测需要成本)
        this.$store.state.count++
        console.log(this.$store.state.count) */
      // 应该通过mutation 核心概念，进行修改数据
      this.$store.commit('addCount', n)
    },
    changeTitle() {
      this.$store.commit('changeTitle', '新标题')
    },
    handleChange() {
      // 调用action
      // this.$store.dispatch('action名字', 666)
      this.$store.dispatch('changeCountAction', 666)
    }
  }
}
</script>

<style lang="css" scoped>
.box {
  border: 3px solid #ccc;
  width: 400px;
  padding: 10px;
  margin: 20px;
}
h2 {
  margin-top: 10px;
}
</style>
